import { Constants } from "../../../../types/types";

type Response = {
  code: number;
  data: any;
  msg: string;
};

class BaseResponse {
  code: number;
  msg: string;
  data: any;

  constructor(code: number, msg: string, data?: any) {
    this.code = code;
    this.msg = msg;
    this.data = data;
  }
}

class SuccessResponse extends BaseResponse {
  constructor(data: any) {
    super(Constants.SuccessCode, "success", data);
  }
}

class ErrorResponse extends BaseResponse {
  constructor(code: number = Constants.ErrorCode, msg: string = "") {
    super(code, msg, "");
  }
}

class MapRes {
  static success({
    code = Constants.SuccessCode,
    data = "",
    msg = "success",
  }: Partial<Response> = {}) {
    return {
      code,
      data,
      msg,
    };
  }

  static error({
    code = Constants.ErrorCode,
    data = "",
    msg = "",
  }: Partial<Response> = {}) {
    return {
      code,
      data,
      msg,
    };
  }
}

export { BaseResponse, SuccessResponse, ErrorResponse, MapRes };
